package com.chw.common.kuyu;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component// 声明bean  交给spring ioc
public class KuYu implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)  {

        //获取跨域的信息
        String origin=request.getHeader("Origin");
        response.setHeader("Access-Control-Allow-Origin",origin);
        //是否允许修改Handel信息
        if(request.getMethod().equals("OPTIONS")){
            //允许放入token
            response.setHeader("Access-Control-Allow-Headers","token");
            response.setStatus(HttpServletResponse.SC_OK);
            return false;
        }
        return true;
    }
}
